package com.future;

import com.jxcell.CellException;
import com.jxcell.View;

import java.io.IOException;

/**
 * 这个是网上说对xls，2003加密的方式，但依赖JDK也是1.8，另外不开源
 *
 * @author future
 * @create 2018-06-01
 */
public class OtherTest {
    /**
     * 读取excel，并进行加密
     *
     * @param url excel文件路径 例：D:\\word.xls
     * @param pwd 加密密码
     */
    public static void encrypt(String url, String pwd) {
        View view = new View();
        try {
            view.read(url);
            view.write(url, pwd);
        } catch (CellException | IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * excel 解密
     *
     * @return void
     * @author lifq
     * @date 2015-3-13 下午02:15:49
     */
    public static void decrypt(String url, String pwd) {
        View view = new View();
        try {
            // read the encrypted excel file
            view.read(url, pwd);

            // write without password protected
            view.write(url);

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void main(String args[]) {
        encrypt("D://test14.xls", "123456");
    }

}